-
Notifications
You must be signed in to change notification settings - Fork 16
/
razzle.config.js
65 lines (55 loc) · 1.85 KB
/
razzle.config.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
'use strict';
const path = require('path');
const makeLoaderFinder = require('razzle-dev-utils/makeLoaderFinder');
const paths = require('razzle/config/paths');
const LoadablePlugin = require('@loadable/webpack-plugin');
const cssLoaderFinder = makeLoaderFinder('css-loader');
module.exports = {
plugins: ['eslint', {
name: 'long-term-caching',
options: {
aggressiveCaching: true,
},
}],
modify(baseConfig, secondArg, webpack) {
const {dev, target} = secondArg;
/* make a copy of config */
const config = Object.assign({}, baseConfig);
const scssLoader = {
loader: require.resolve('sass-loader'),
options: {
sourceMap: dev,
},
};
config.module.rules.filter(cssLoaderFinder).forEach((rule) => {
const isCssModuleRule = !rule.test.test('module.css');
const scssExclude = [paths.appBuild];
let scssTest = /\.s[ac]ss$/;
if (isCssModuleRule) {
scssTest = /\.module\.s[ac]ss$/;
} else {
scssExclude.push(/\.module\.s[ac]ss$/);
}
// Use default configs
config.module.rules.push({
test: scssTest,
exclude: scssExclude,
use: [
...rule.use,
scssLoader,
]
});
});
if (target !== 'node') {
config.plugins.push(new LoadablePlugin({
outputAsset: false,
writeToDisk: {
filename: path.resolve(__dirname, 'build'),
},
}));
}
// adding ./src to module resolver so I can import modules with absolute paths
config.resolve.modules.push('./src');
return config;
},
};